package com.sinoglobal.ningxia.activity.shop;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.sinoglobal.ningxia.R;
import com.sinoglobal.ningxia.activity.IBase;
import com.sinoglobal.ningxia.activity.base.BaseActivity;
import com.sinoglobal.ningxia.beans.ConsigneeInfoVo;
import com.sinoglobal.ningxia.downdata.imp.RemoteImpl;
import com.sinoglobal.ningxia.frame.FlyApplication;
import com.sinoglobal.ningxia.http.Code;
import com.sinoglobal.ningxia.utils.MContants;

/**
 * @author zbl
 * @createdate 2014-7-9 下午3:59:45
 * @Description:点击进入"我的"里面单个物品的物流和个人基本的详情信息
 */
public class CashGoodsInfoActivity extends BaseActivity implements IBase {
    private TextView nameEd;// 姓名
    private TextView tel;// 电话
    private TextView address;// 地址
    private TextView remark;// 备注
    private TextView companyInfo;// 物流公司
    private TextView wayBill;// 运单号码
    private TextView query;// 查询
    private Intent intent;
    private String bogId;
    private String logCode;// 物流编码
    private String wayBillNum;// 运单号码

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        isTemplate = true;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cash_goods_info);
        openChenJInShi();//开启沉浸式
        titleView.setText(R.string.deliver_goods);
        // 获取订单号
        intent = getIntent();
        bogId = intent.getStringExtra("bog_id");

        init();
        loadInfo();// 从网络获取数据
        showListener();

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.cash_goods_info, menu);
        return true;
    }

    @Override
    public void init() {
        nameEd = (TextView) findViewById(R.id.c_name_ed);
        tel = (TextView) findViewById(R.id.c_tel);
        address = (TextView) findViewById(R.id.c_address);
        remark = (TextView) findViewById(R.id.c_remark);
        companyInfo = (TextView) findViewById(R.id.company_info);
        wayBill = (TextView) findViewById(R.id.waybill_info);
        query = (TextView) findViewById(R.id.query);
        query.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

    }

    @Override
    public void showListener() {
        // 当有物流信息时点击查询物流信息
        query.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                intent = new Intent(CashGoodsInfoActivity.this, CashGoodsLogisticsActivity.class);
                intent.putExtra("companyInfo", logCode);
                intent.putExtra("waybillInfo", wayBillNum);
                startActivity(intent);
            }
        });

    }

    // 加载 收货人信息
    private void loadInfo() {
        new ItktAsyncTaskWithDialog<Void, Void, ConsigneeInfoVo>(getString(R.string.loading), true, true) {

            @Override
            public ConsigneeInfoVo before(Void... params) throws Exception {
                return RemoteImpl.getInstance().getConsigneeInfo(FlyApplication.userId, bogId);
            }

            @Override
            public void after(ConsigneeInfoVo result) {
                if (result != null) {
                    if (Code.CODE_SUCCESS != result.getCode()) {
                        showShortToastMessage(result.getMessage());
                    } else {
                        nameEd.setText(result.getUser_name());
                        tel.setText(result.getNumber());
                        address.setText(result.getAddress());
                        remark.setText(result.getRemark());
                        if (!MContants.EMPTY_STRING.equals(result.getCom_name()) && !MContants.EMPTY_STRING.equals(result.getPostal_num())) {
                            companyInfo.setText(result.getCom_name());
                            wayBill.setText(result.getPostal_num());
                            query.setVisibility(View.VISIBLE);
                            logCode = result.getCompany();
                            wayBillNum = result.getPostal_num();
                        }

                    }
                }
            }

            @Override
            public void exception() {

            }

        }.execute();
    }

}
